package cn.kgc.ssm.service.impl;

import cn.kgc.ssm.dto.RecruitPageDTO;
import cn.kgc.ssm.entity.Recruit;
import cn.kgc.ssm.mapper.RecruitMapper;
import cn.kgc.ssm.response.ResponseResult;
import cn.kgc.ssm.service.RecruitService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 课工场
 * @date 2024/11/21
 * @description
 */
@Service
public class RecruitServiceImpl implements RecruitService {

    @Autowired
    private RecruitMapper recruitMapper;

    @Override
    public ResponseResult recruitPage(RecruitPageDTO recruitDTO) {

        PageHelper.startPage(recruitDTO.getPage(), recruitDTO.getLimit());
        List<Recruit> tableData = recruitMapper.selectRecruits(recruitDTO.getPosition(), recruitDTO.getDept());

        long total = new PageInfo<Recruit>(tableData).getTotal();

        return ResponseResult.success().data(tableData).count(total);
    }

    @Override
    public ResponseResult addRecruit(Recruit recruit) {

        recruitMapper.insertRecruit(recruit);

        return ResponseResult.success();
    }

    @Override
    public ResponseResult editRecruitStatus(Integer id, Integer isDelete, Integer version) {

        recruitMapper.updateRecruitStatus(id, isDelete, version);
        return ResponseResult.success();
    }

    @Override
    public ResponseResult editRecruit(Recruit recruit) {

        recruitMapper.updateRecruit(recruit);
        return ResponseResult.success();
    }

    @Transactional
    @Override
    public ResponseResult deleteRecruit(List<Integer> ids) {

        recruitMapper.deleteRecruit(ids);
        return ResponseResult.success();
    }

    @Override
    public ResponseResult recruitList(Integer limit) {

        List<Recruit> recruits = recruitMapper.selectRecruitList(limit);
        return ResponseResult.success().data(recruits);
    }
}
